package com.docking.heylo.web.conf;

import com.docking.heylo.web.interceptor.AuthorityInterceptor;
import com.docking.heylo.web.interceptor.GlobalizationInterceptor;
import com.docking.heylo.web.interceptor.WebInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;


@Configuration
public class WebAppConfig implements WebMvcConfigurer {

    @Autowired
    private AuthorityInterceptor authorityInterceptor;

    @Autowired
    private WebInterceptor webInterceptor;

    @Autowired
    private GlobalizationInterceptor globalizationInterceptor;

    private List<String> excludePath = new ArrayList<String>(){{
        add("/sendEnrollmentVerCode");
        add("/enrollment");
        add("/login");
        add("/submitPhoneAndPassword");
        add("/public/*");
        add("/sendRetrievePassword");
        add("/retrievePassword");
        add("/lastVersion");
        add("/protocol/*");
        add("/versionCheck");
    }};


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(globalizationInterceptor);
        registry.addInterceptor(webInterceptor);
        registry.addInterceptor(authorityInterceptor).excludePathPatterns(excludePath);
    }


//    @Bean
//    public HttpMessageConverters fastJsonHttpMessageConverters(){
//        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
//        FastJsonConfig config = new FastJsonConfig();
//        config.setSerializerFeatures(
//                SerializerFeature.PrettyFormat,
//                SerializerFeature.WriteNullListAsEmpty,                 // 将Collection类型字段的字段空值输出为[]
//                SerializerFeature.WriteNullStringAsEmpty,               // 将字符串类型字段的空值输出为空字符串
//                SerializerFeature.WriteNullNumberAsZero,                // 将数值类型字段的空值输出为0
//                SerializerFeature.WriteDateUseDateFormat,
//                SerializerFeature.DisableCircularReferenceDetect        // 禁用循环引用
//        );
//        converter.setFastJsonConfig(config);
//        List<MediaType> fastMediaTypes = new ArrayList<>();
//        fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
//        converter.setSupportedMediaTypes(fastMediaTypes);
//        return new HttpMessageConverters(converter);
//    }




}
